﻿using OMG.Fill.Potato.Model;
using OMG.Fill.Potato.Services;
using ProjectShare;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Security;

namespace OMG.Fill.Potato.UI.Controllers
{
    public class AccountController : ApiController
    {
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResResult<UserModel> Post(LoginModel model)
        {
            ResResult<UserModel> userinfo = new ResResult<UserModel>();
            UserServices user = new UserServices();
            userinfo = user.LoginUser(model.Account, model.Passwords);
            if (userinfo.model != null)
            {
                FormsAuthentication.SetAuthCookie(userinfo.model.Id.ToString(), model.IsRember);
            }
            return userinfo;
        }
        /// <summary>
        /// 退出登录
        /// </summary>
        /// <returns></returns>
        //[ApiActionAuthorize("退出登录")]
        //[ApiActionException]
        public ResResult<string> Get()
        {
            var s = HttpContext.Current.Request[FormsAuthentication.FormsCookieName];
            FormsAuthentication.SignOut();
            return new ResResult<string> { status = DefaultKey.SuccessResult, message = "已退出！" };
        }
    }
    public class LoginModel
    {
        public string Account { get; set; }
        public string Passwords { get; set; }
        public bool IsRember { get; set; }
    }
}
